package org.com.gamemall.Config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {
//    @Bean
//    public FanoutExchange fanoutExchange() {
//        //创建交换机
//        return new FanoutExchange("testfanout");
//    }
//
//    @Bean
//    public Queue fanoutque3() {
//        //创建队列
//        return new Queue("fanout.que3");
//    }
//
//    @Bean
//    public Binding fanoutBinding3(Queue fanoutque3, FanoutExchange fanoutExchange)
//    //绑定队列和交换机
//    {
////    return BindingBuilder.bind(fanoutque3).to(fanoutExchange);
//        return BindingBuilder.bind(fanoutque3()).to(fanoutExchange());
//
//    }
// 死信交换机
@Bean
public DirectExchange dlxExchange() {
    return new DirectExchange("dlx.exchange");
}

    // 死信队列
    @Bean
    public Queue dlxQueue() {
        return new Queue("dlx.queue", true);
    }

    // 绑定死信队列到死信交换机
    @Bean
    public Binding dlxBinding() {
        return BindingBuilder.bind(dlxQueue())
                .to(dlxExchange())
                .with("dlx");
    }

    // 延迟队列（设置TTL和死信配置）
    @Bean
    public Queue delayQueue() {
        return QueueBuilder.durable("delay.queue")
                .withArgument("x-message-ttl", 5000) // 5秒TTL
                .withArgument("x-dead-letter-exchange", "dlx.exchange") // 死信交换机
                .withArgument("x-dead-letter-routing-key", "dlx") // 死信路由键
                .build();
    }
}
